
*** figure.do produce the non-linear figure 
*** input: temp 
cd $datapath 

use tempi, clear 


global tax_var inter_1 inter_2 inter_3 inter_4 inter_5 inter_6 inter_7 inter_8  inter_10 
*
global control inter_tarif inter_ldistw inter_lgdpc cty_*
* tarif ldistw lgdpc dum_hines q_1 q_2 q_3 q_4 q_5 q_6 q_7 q_8 q_10
*interdum_hines 

xtreg luv type $tax_var $control $condition, fe i(fpt) cluster(pays) nonest


forvalue i = 1(1)8{
g coef_`i'=_b[inter_`i']
g se_`i'=_se[inter_`i']
}
g coef_9=0
g se_9=0
forvalue i = 10(1)10{
g coef_`i'=_b[inter_`i']
g se_`i'=_se[inter_`i']
}

replace emtr=emtr*100
forvalue i = 1(1)10{
egen emtr_mean_`i'_=median(emtr) if q_`i'==1 
egen emtr_min_`i'_=min(emtr) if q_`i'==1 
egen emtr_max_`i'_=max(emtr) if q_`i'==1 
}

forvalue i = 1(1)10{
egen emtr_mean_`i'=max(emtr_mean_`i'_) if q_`i'==1 
egen emtr_min_`i'=max(emtr_min_`i'_) if q_`i'==1 
egen emtr_max_`i'=max(emtr_max_`i'_) if q_`i'==1 
}


save temp, replace 

use temp, clear
collapse (max) coef_* se_*  emtr_*
forvalue i = 1(1)10{
g f_`i'=coef_`i'
g d_`i'= se_`i' 
}
keep f_* d_* emtr_*

g a=1
reshape long f_ d_  emtr_mean_ emtr_max_ emtr_min_, i(a) j(quint)
g up=f_ + 1.96*d_
g do=f - 1.96*d_

g l=0
sort quint
gr tw  (rarea  up do quint, col(gs15)) (line l quint, lc(gs12) lp(dash) lw(thin)) (line f_  quint , lc(green))(scatter f_  quint , ms(o) mc(green)) ,  ytitle("Price gap intrafirm - arm's-length") legend(off)  xtitle("Tax decile") ylabel(, angle(0)) xlabel(1(1)10)

forval x = 1(1)10 {
sum emtr_mean_ if quint==`x'
local y`x' = round(r(mean),0.1)
 }
 label define cat 1 "`y1'"  2 "`y2'"  3 "`y3'"  4 "`y4'"  5 "`y5'"  6 "`y6'"  7 "`y7'"  8 "`y8'"  9 "`y9'"  10 "`y10'"
 label values quint cat

*gr tw  (rarea  up do quint, col(gs15)) (line l quint, lc(gs12) lp(dash) lw(thin)) (line f_  quint , lc(green))(scatter f_  quint , ms(o) mc(green)) ,  ytitle("Price gap intrafirm - arm's-length") legend(off)  xtitle("Tax decile") ylabel(, angle(0)) xlabel(1(1)10)
*graph export "$graphpath\$threshold\splin_tax_decile$lab.eps", replace 

*replace emtr_mean_=round(emtr_mean_,0.1)
*gr tw  (rarea  up do quint, col(gs15)) (line l quint, lc(gs12) lp(dash) lw(thin)) (line f_  quint , lc(green))(scatter f_  quint , mlabel(emtr_mean_) ms(o) mc(green)) ,  ytitle("Price gap intrafirm - arm's-length") legend(off)  xtitle("Tax decile") ylabel(, angle(0)) xlabel(1(1)10)
*graph export "$graphpath\$threshold\splin_tax_decilelabel$lab.eps", replace 

gr tw  (rarea  up do quint, col(gs15)) (line l quint, lc(gs12) lp(dash) lw(thin)) (line f_  quint , lc(green))(scatter f_  quint , ms(o) mc(green)) ,  ytitle("Price gap intrafirm - arm's-length") legend(off)  xtitle("Median tax rate in the tax decile") ylabel(, angle(0)) xlabel(1(1)10, valuelabel)
graph export "$graphpath\figure$lab.eps", replace 


*gr tw  (rarea  up do emtr_mean_, col(gs15)) (line l emtr_mean_, lc(gs12) lp(dash) lw(thin)) (line f_  emtr_mean_ , lc(green))(scatter f_  emtr_mean_ , ms(o) mc(green)) ,  ytitle("Price gap intrafirm - arm's-length") legend(off)  xtitle("Median tax rate in the tax decile") ylabel(, angle(0)) xlabel(#7)
*graph export "$graphpath\$threshold\splin_tax_emtr$lab.eps", replace 
